﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KTV项目
{
    public partial class xinzen : Form
    {
        Bestdao dao = new Bestdao();
        public xinzen()
        {
            InitializeComponent();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void xinzen_Load(object sender, EventArgs e)
        {
            //将歌手类别的的数据绑定到下拉框中
            radioButton1.Checked = true;
            string sql = "select singertype_name from singer_type";
            comboBox1.DataSource = dao.table(sql);
            comboBox1.DisplayMember = "singertype_name";
            comboBox1.ValueMember = "singertype_name";
        }
        string lujing;
        private void button1_Click(object sender, EventArgs e)
        {
            //设置歌手图标的的文件
            OpenFileDialog od = new OpenFileDialog();
            od.InitialDirectory = "D:\\Songs";
            od.Filter = "jpg|*.jpg|png|*.png";
            DialogResult dr = od.ShowDialog();
            if (dr == DialogResult.OK)
            {
                //将数据路径用一个全局变量来接收存储
                lujing = od.FileName;
                //并同时告诉图片显示框的图片路径
                pictureBox1.ImageLocation = lujing;
                
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //先将歌手信息的性别以及歌手类型判断出来
            string sex;
            int lei;
            //判断用户选择的性别选项
           if(radioButton1.Checked == true){
                sex = "男";
            }
            else
            {
                sex = "女";
            }
           //判断用户选择的歌曲类别选项
            if (comboBox1.SelectedIndex == 0)
            {
                lei = 1;
            }
            else if (comboBox1.SelectedIndex==1)
            {
                lei = 2;
            }
            else
            {
                lei = 3;
            }
            //将歌手的所有信息增加到数据库存储
            string sql =string.Format(@"insert singer_info values
('{0}', {1}, '{2}', '{3}','{4}')",textBox1.Text,lei,sex,lujing,textBox2.Text);
            int he = dao.query(sql);
            if (he!=0)
            {
                MessageBox.Show("增加成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("增加失败");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //关闭本窗体
            this.Close();
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
